#接口规范
#{
   # "code":400,
   #  "message":"",
   #  "data":{
   #      "name":"",
   #      "age":""
   #  }
# }

from flask import jsonify

class HttpCode(object):
    ok=200
    unautherror=403
    paramerror=400
    methoderror=405
    servererror=500

def restful_result(code,message,data):
    return jsonify({"code":code,"message":message,"data":data or {}})

def success(message="",data=None):
    return restful_result(code=HttpCode.ok,message=message,data=data)

def unauth_error(message="",data=None):
    return restful_result(code=HttpCode.unautherror,message=message,data=data)

def params_error(message="",data=None):
    return restful_result(code=HttpCode.paramerror,message=message,data=data)

def server_error(message="",data=None):
    return restful_result(code=HttpCode.servererror,message=message or '服务器内容错误',data=data)

